//
//  LKEmoticonPageView.swift
//  LKWeibo
//
//  Created by like on 16/8/18.
//  Copyright © 2016年 like. All rights reserved.
//

import UIKit

// cell 可重用标示符
private let LKEmoticonPageViewCellId = "HMEmoticonPageViewCellId"

class LKEmoticonPageView: UICollectionView {

    override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
        super.init(frame: frame, collectionViewLayout: UICollectionViewFlowLayout())
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //设置UI
    private func setupUI(){
        
        dataSource = self
        registerClass(LKEmoticonPageViewCell.self, forCellWithReuseIdentifier: LKEmoticonPageViewCellId)
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        let layout = self.collectionViewLayout as! UICollectionViewFlowLayout
        //item 大小
        layout.itemSize = self.frame.size
        //水平 垂直 间距
        layout.minimumLineSpacing = 0
        layout.minimumInteritemSpacing = 0
        //滚动方向
        layout.scrollDirection = .Horizontal
        
    }
    
    
}


extension LKEmoticonPageView: UICollectionViewDataSource{
    
    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        return LKEmoticonTools.sharedTools.allEmoticons.count
    }
    
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return LKEmoticonTools.sharedTools.allEmoticons[section].count
    }
    
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(LKEmoticonPageViewCellId, forIndexPath: indexPath) as! LKEmoticonPageViewCell
        
        cell.indexPath = indexPath
        
        cell.emoticons = LKEmoticonTools.sharedTools.allEmoticons[indexPath.section][indexPath.item]
        
        return cell
    }
    
    
    
    
}